// 视频自定义验证装饰器
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';

export function IsVideoFile(validationOptions?: ValidationOptions) {
  return function (object: Object, propertyName: string) {
    registerDecorator({
      name: 'isVideoFile',
      target: object.constructor,
      propertyName,
      options: validationOptions,
      validator: {
        validate(value: any, args: ValidationArguments) {
          const allowedTypes = ['video/mp4', 'video/avi', 'video/mpeg', 'video/quicktime'];
          return value && value.mimetype && allowedTypes.includes(value.mimetype);
        },
        defaultMessage(args: ValidationArguments) {
          return '文件必须是视频（MP4, AVI, MPEG, QuickTime）';
        }
      }
    });
  };
}
